#include <QgsSimulation/Thread.h>
using SimulationCore::QgsSimulation::DataManageTool;
using SimulationCore::QgsSimulation::Thread;
using SimulationCore::QgsSimulation::RunWorker;

DataManageTool::DataManageTool(QObject * parent)
	:QObject(parent)
{
}

Thread::Thread(QObject * parent)
	: QThread(parent)
{
}

Thread::Thread(DataManageTool & tool, QObject * parent)
	: QThread(parent), m_tool_(&tool)
{
	connect(this->m_tool_, &DataManageTool::tool_progress, [&](QString text, double progress) {
		emit this->thread_progress(text, progress);
	});

	connect(this->m_tool_, &DataManageTool::tool_finished, [&](ToolStatus status) {
		emit this->thread_finished(status);
	});
}

void Thread::SetTool(DataManageTool & tool)
{
	this->m_tool_ = &tool;

	connect(this->m_tool_, &DataManageTool::tool_progress, [&](QString text, double progress) {
		emit this->thread_progress(text, progress);
	});

	connect(this->m_tool_, &DataManageTool::tool_finished, [&](ToolStatus status) {
		emit this->thread_finished(status);
	});
}

void Thread::run()
{
	this->m_tool_->start();
}



RunWorker::RunWorker()
{
}

RunWorker::RunWorker(DataManageTool & tool)
	: m_tool_(&tool)
{
}


void RunWorker::SetTool(DataManageTool & tool)
{
	this->m_tool_ = &tool;
}

void RunWorker::run()
{
	this->m_tool_->start();
	delete this->m_tool_;
	this->m_tool_ = nullptr;
}




